package com.java.zhuiyun.api.video_manage.controller;

import com.java.zhuiyun.api.file_manager.entity.FileManager;
import com.java.zhuiyun.api.video_manage.service.VideoManageService;
import com.java.zhuiyun.common.response.CommonResult;

import com.java.zhuiyun.util.pageUtil.PageRequest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName videoManageController
 * @Description TODO
 * @Author MJL
 * @Date 2023/8/21 19:43
 **/
@RestController
@RequestMapping("/videoManage")
public class VideoManageController {
    @Resource
    VideoManageService videoManageService;

    @Resource
    JavaMailSender javaMailSender;

    /**
    * @Author MJL
    * @Description todo 查询出所有尚未审核文件
    * @Date 2023/8/21 19:47
    * @Return  * @param null
    */
    @GetMapping("/queryVideoManage")
    public CommonResult queryVideoManage(FileManager fileManager, PageRequest pageRequest){
        return CommonResult.ok(videoManageService.queryVideoManage(fileManager,pageRequest));
    }

    /**
    * @Author MJL
    * @Description todo 将尚未审核的视频进行审核通过
    * @Date 2023/8/22 10:25
    * @Return  * @param null
    */
    @DeleteMapping("/auditSucceed")
    public CommonResult auditSucceed(FileManager fileManager){
        int i = videoManageService.auditSucceed(fileManager);
        if (i>0){
            return CommonResult.ok("审核通过");
        } else {
            return CommonResult.error("审核系统出现先问题，请及时联系管理员");
        }
    }

    /**
    * @Author MJL
    * @Description todo 将尚未审核的视频进行审核失败
    * @Date 2023/8/22 11:21
    * @Return  * @param null
    */
    @DeleteMapping("/auditFail")
    public CommonResult auditFail(FileManager fileManager) {
        int i = videoManageService.auditFail(fileManager);
        if (i>0){
            return CommonResult.ok("审核失败");
        } else {
            return CommonResult.error("审核系统出现先问题，请及时联系管理员");
        }
    }

    /*/**
    * @Author MJL
    * @Description 获取到视频Id,进行视频预览
    * @Date 2023/8/28 20:22
    * @Return  * @param null
    */
    @GetMapping("/Preview/{fileManagerId}")
    public CommonResult Preview (@PathVariable Integer fileManagerId) {
        return CommonResult.ok(videoManageService.Preview(fileManagerId));
    }

    /*/**
    * @Author MJL
    * @Description 邮箱通知
    * @Date 2023/8/29 12:53
    * @Return  * @param null
    */
    @GetMapping("/send/mail")
    public Object sendMail (String from,String to,String title,String body) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("2193218465@qq.com");
        simpleMailMessage.setTo("2193218465@qq.com");
        simpleMailMessage.setText("成功");
        simpleMailMessage.setSubject("发送成功");
        System.out.println("开始发送");
        javaMailSender.send(simpleMailMessage);
        System.out.println("发送完成");
        return "ok";

    }
}
